home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / AOCE Sample Code / PowerTalk Access Modules / Sample CSAM / Sources / SKEL•CSAM.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-28  |  8.6 KB  |  252 lines  |  [TEXT/MPS ]

  1. /* ==========================================================================
  2.     Action routines for the LDAP CSAM.
  3.  
  4.     Written by: Gavin Eadie • The University of Michigan Information Systems
  5.           Phone: (313) 936-0816
  6.      AppleLink: A67
  7.       Internet: gavin@umich.edu
  8.          
  9.         History:    Apr18/91    1.0d1        Start
  10.                     Oct22/91                Start again (Gav)
  11.                     Apr22/92 1.0d3        Finally get back to this (Gav)    
  12.                     Apr29/92 1.0d4        ... making progress (Gav)
  13.                     May09/92 1.0d5     ... WWDC Version (Gav)
  14.                     May22/92 1.0d6     post WWDC changes [dash->DSAM] ... Gav
  15.                     Aug14/92 1.0d7     OCE Alpha 8 changes - MANY!! (Gav)
  16.                     Aug24/92 1.0a1     version to alpha - continuing changes (Gav)
  17.                     Sep08/92    1.0a2        _Procs, _Parse & _Authi split off ... (Gav)
  18.                     Sep22/92    1.0a3        Return the stubs of the _Procs, _Parse &
  19.                                             _Authi routines to this file because the
  20.                                             periodic timer that drives asynch stuff
  21.                                             lives here too.
  22.                     Jan04/93    1.0a10    First try with AOCE a13 ... Gav
  23.                     Jan21/93    1.0a13    reduce to 7 (iconCount) icon resources ... Gav
  24.                     Jan27/93    1.0a14    no revisions for AOCE 1.0a14 ... Gav
  25.                     Mar10/93    1.0a16    all MacsBug calls removed ... Gav
  26.                     Mar16/93 1.0a17    revisions for AOCE 1.0b1 ... Gav
  27.                     Jun01/93 1.0a23    remove «displayName» from pSect ... Gav
  28.  
  29.                     Jan18/94 1.0b20    increase audit log to 128 entries ... Gav
  30.  
  31.     ==========================================================================    */
  32.  
  33. #include "Headers.H"
  34.  
  35. OSErr Locate_Icon(struct Icon_Data * Icon, ResType Type);
  36.  
  37. //    --------------------------------------------------------------------------
  38. //        CSAM_Open • Initialise the dash code.
  39. //        
  40. //        Since we are really a driver, we need to grab some working memory
  41. //        and link it to the dCtl - we do that first, then we initialize the
  42. //        various CSAM attributes.
  43. //    --------------------------------------------------------------------------
  44. OSErr CSAM_Open(CntrlParam * ctlPB, DCtlPtr dCtl) {
  45.     register MyDashGlobals * dGlobals;
  46.     Handle            displayName;            // Display Name for the CSAM
  47.     DirParamBlock    Dir_Param;
  48.     OSErr result;
  49.  
  50. //    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  51. //        if there is no working storage, get some - if there is, return happy.
  52. //    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  53.     if (nil == dCtl->dCtlStorage) {
  54.         if (nil == (dCtl->dCtlStorage = NewHandleSysClear(sizeof(MyDashGlobals))))
  55.             result = memFullErr;                // no memory - no Globals
  56.         else {
  57.             HLock(dCtl->dCtlStorage);
  58.             
  59.             dGlobals = (MyDashGlobals *)(*dCtl->dCtlStorage);
  60.  
  61. #ifdef AUDIT
  62.             dGlobals->Audit_Ptr = InitAudit('ldap', 128, true, false);
  63. #endif
  64.             Audit_PString('CSAM', "\pCSAM_Open: Started");
  65.  
  66.             dGlobals->CSAM_Q.qFlags = 0;
  67.             dGlobals->CSAM_Q.qHead = nil;
  68.             dGlobals->CSAM_Q.qTail = nil;
  69.             
  70. //    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  71. //        get the display name ... use an 'rstr' resource
  72. //    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  73.             displayName = Get1NamedResource('rstr', "\pDisplay Name");
  74.             if (nil == displayName) {
  75.                 Audit_PString('CSAM', "\pCSAM_Open: Get('Display Name')");
  76.                 return (memFullErr);
  77.             }
  78.             HLock(displayName);
  79.             DetachResource(displayName);
  80.     
  81. //    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  82. //        get the icon resources (7 of them) ...
  83. //    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  84.             Locate_Icon(&dGlobals->Icon[0], 'ICN#');
  85.             Locate_Icon(&dGlobals->Icon[1], 'icl8');
  86.             Locate_Icon(&dGlobals->Icon[2], 'icl4');
  87.  
  88.             Locate_Icon(&dGlobals->Icon[3], 'ics#');
  89.             Locate_Icon(&dGlobals->Icon[4], 'ics8');
  90.             Locate_Icon(&dGlobals->Icon[5], 'ics4');
  91.  
  92.             Locate_Icon(&dGlobals->Icon[6], 'SICN');
  93.             
  94.             dGlobals->ldap_Other_Hdl = Get1Resource('rstr', otherRStrID);
  95.             if (nil != dGlobals->ldap_Other_Hdl && noErr == ResError()) {
  96.                 HLock(dGlobals->ldap_Other_Hdl);
  97.                 DetachResource(dGlobals->ldap_Other_Hdl);
  98.             }
  99.             else {
  100.                 Audit_PString('CSAM', "\pMissing 'ldap Other' RStr");
  101.                 return (memFullErr);
  102.             }
  103.             
  104.             dGlobals->Delta_Count = 0;                // initialize changes counter
  105.  
  106.             Dir_Param.instantiateDSAMPB.dsamName = (RStringPtr)*displayName;
  107.             Dir_Param.instantiateDSAMPB.dsamKind = skelType;
  108.             Dir_Param.instantiateDSAMPB.dsamData = (Ptr)dGlobals;
  109. #ifdef UNIVERSAL_HEADERS
  110.             Dir_Param.instantiateDSAMPB.dsamDirProc = (DSAMDirUPP)CSAM_Procs;
  111.             Dir_Param.instantiateDSAMPB.dsamDirParseProc    = (DSAMDirParseUPP)CSAM_Parse;
  112. #else
  113.             Dir_Param.instantiateDSAMPB.dsamDirProc = (ProcPtr)CSAM_Procs;
  114.             Dir_Param.instantiateDSAMPB.dsamDirParseProc    = (ProcPtr)CSAM_Parse;
  115. #endif
  116.             result = DirInstantiateDSAM(&Dir_Param);
  117.         }
  118.     }
  119.     return (ctlPB->ioResult = result);
  120. }
  121.  
  122.  
  123. //    --------------------------------------------------------------------------
  124. //        CSAM_Control • Called by periodic timer.
  125. //    --------------------------------------------------------------------------
  126. OSErr CSAM_Control(CntrlParam * ctlPB, DCtlPtr dCtl) {
  127. #pragma unused (ctlPB)
  128.     MyDashGlobals * dGlobals = (MyDashGlobals *)(*dCtl->dCtlStorage);
  129.     
  130.     if (nil != dGlobals->CSAM_Q.qHead) {
  131.         if (noErr == Dequeue(dGlobals->CSAM_Q.qHead, &(dGlobals->CSAM_Q))) {
  132.         }
  133.     }
  134.  
  135.     return (noErr);
  136. }
  137.  
  138.  
  139. /*    --------------------------------------------------------------------------
  140.         CSAM_Prime • No longer called (after OCE alpha 8).
  141.     --------------------------------------------------------------------------    */
  142. OSErr CSAM_Prime(CntrlParam * ctlPB, DCtlPtr dCtl) {
  143. #pragma unused (ctlPB)
  144.     MyDashGlobals * dGlobals = (MyDashGlobals *)(*dCtl->dCtlStorage);
  145.     
  146.     return (noErr);
  147. }
  148.  
  149.  
  150. /*    --------------------------------------------------------------------------
  151.         CSAM_Status • No longer called (after OCE alpha 8).
  152.     --------------------------------------------------------------------------    */
  153. OSErr CSAM_Status(CntrlParam * ctlPB, DCtlPtr dCtl) {
  154. #pragma unused (ctlPB)
  155.     MyDashGlobals * dGlobals = (MyDashGlobals *)(*dCtl->dCtlStorage);
  156.     
  157.     return (noErr);
  158. }
  159.  
  160.  
  161. /*    --------------------------------------------------------------------------
  162.         CSAM_Close • release storage.
  163.     --------------------------------------------------------------------------    */
  164. OSErr CSAM_Close(CntrlParam * ctlPB, DCtlPtr dCtl) {
  165. #pragma unused (ctlPB)
  166.     MyDashGlobals * dGlobals = (MyDashGlobals *)(*dCtl->dCtlStorage);
  167.     
  168.     if (nil != dGlobals) {
  169.         short i;
  170.  
  171.         for (i = 0; i < iconCount; i++) {
  172.             if (nil != dGlobals->Icon[i].iconHandle) {
  173.                 HUnlock(dGlobals->Icon[i].iconHandle);
  174.                 ReleaseResource(dGlobals->Icon[i].iconHandle);
  175.             }
  176.         }
  177.         DisposHandle(dCtl->dCtlStorage);
  178.         dCtl->dCtlStorage = nil;
  179.     }
  180.  
  181.     return (noErr);
  182. }
  183.  
  184.  
  185. /*    --------------------------------------------------------------------------
  186.         CSAM_Procs • get and information functions
  187.         
  188.     --------------------------------------------------------------------------    */
  189. pascal OSErr CSAM_Procs(void * dashData, DirParamBlockPtr ds_PB, Boolean async) {
  190.     register MyDashGlobals * dGlobals = (MyDashGlobals * )dashData;
  191.     OSErr    Dir_Error = kOCEParamErr;
  192.  
  193.     Audit_PString('PROX', (async ? "\p----->(async)" : "\p----->(synch)"));
  194.  
  195.     if (async) {
  196. //        Enqueue((QElemPtr) ds_PB, &(dGlobals->CSAM_Q));
  197.         Dir_Error = Dir_Procs(dGlobals, ds_PB);
  198.         io_Complete(ds_PB, Dir_Error);
  199.  
  200.         return (noErr);
  201.     }
  202.     else
  203.         return (ds_PB->header.ioResult = Dir_Procs(dGlobals, ds_PB));
  204.  
  205. }
  206.  
  207.  
  208. /*    --------------------------------------------------------------------------
  209.         CSAM_Parse • parse functions
  210.         
  211.     --------------------------------------------------------------------------    */
  212. pascal OSErr CSAM_Parse(void * dashData, DirParamBlockPtr ds_PB, Boolean async) {
  213.     register MyDashGlobals * dGlobals = (MyDashGlobals * )dashData;
  214.     OSErr    Dir_Error = kOCEParamErr;
  215.  
  216.     Audit_PString('PARZ', (async ? "\p----->(async)" : "\p----->(synch)"));
  217.  
  218.     if (async) {
  219. //        Enqueue((QElemPtr) ds_PB, &(dGlobals->CSAM_Q));
  220.         Dir_Error = Dir_Parse(dGlobals, ds_PB);
  221.         io_Complete(ds_PB, Dir_Error);
  222.  
  223.         return (noErr);
  224.     }
  225. //    else
  226.         return (ds_PB->header.ioResult = Dir_Parse(dGlobals, ds_PB));
  227.  
  228. }
  229.  
  230.  
  231. /*    --------------------------------------------------------------------------
  232.         Locate_Icon • utility function
  233.  
  234.     --------------------------------------------------------------------------    */
  235. OSErr Locate_Icon(struct Icon_Data * Icon, ResType Type) {
  236.     OSErr    Res_Error = noErr;
  237.     
  238.     Icon->iconType = Type;
  239.     Icon->iconLength = 0;
  240.     Icon->iconHandle = Get1Resource(Type, 1000);
  241. //    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  242. //        don't forget that ResError() can return noErr when GetResource
  243. //        doesn't find the resource so check for both possibilities ...
  244. //    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  245.     if (nil != Icon->iconHandle && noErr == (Res_Error = ResError())) {
  246.         HLock(Icon->iconHandle);
  247.         DetachResource(Icon->iconHandle);
  248.         Icon->iconLength = GetHandleSize(Icon->iconHandle);
  249.     }
  250.     return (Res_Error);
  251. }
  252.